using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace FeatureWally.Client.Handlers {
    public class ShortCutHandler {
        private static ShortCutHandler _current = null;

        private ShortCutHandler() {
            _currentShortCuts = new ArrayList();
        }

        public static ShortCutHandler Current {
            get {
                if (_current == null)
                    _current = new ShortCutHandler();
                return _current;
            }
        }

        private ArrayList _currentShortCuts;

        public void RegisterCommand(TextBoxBase box, FWEditCommand command, ToolStripMenuItem menu) {
            FWShortCut item = new FWShortCut();
            item.Box = box;
            item.Command = command;
            item.Menu = menu;
            if (menu != null)
                menu.Enabled = true;
            _currentShortCuts.Add(item);
        }

        public void ClearCommands() {
            foreach (FWShortCut item in _currentShortCuts) {
                if (item.Menu != null)
                    item.Menu.Enabled = false;
            }
            _currentShortCuts.Clear();
        }

        public TextBoxBase GetMyCommandObject(FWEditCommand command) {
            TextBoxBase result = null;
            foreach (FWShortCut item in _currentShortCuts) {
                if (item.Command.Equals(command))
                    result = item.Box;
            }
            return result;
        }
    }

    public class FWShortCut {
        public TextBoxBase Box;
        public FWEditCommand Command;
        public ToolStripMenuItem Menu;
    }

    public enum FWEditCommand {
        Undo,
        Redo,
        Cut,
        Copy,
        Paste,
        SelectAll
    }
}
